remove(list=ls())
###required packages
library(fixest);library(ggmap);library(raster);library(dplyr);library(wru); 
library(tidycensus);library(tidyverse);library(zippeR);library(sf);library(tigris);library(stringr)
library(httr); library(jsonlite);library(AER);library(knitr);library(terra);library(logr);library(sp)
options(tigris_use_cache = TRUE)

### replace with your working directory ###
twd <- "~/Dropbox/Tornado Turnout/replication_material/"
#twd<-"/Users/throwesd/Dropbox/Coauthored Papers/Tornado Turnout/replication_material/"

###################################
### Build the data from scratch ###
###################################

### Build data

log_open(paste(twd,"build_data.log", sep = "" ))

source(paste(twd,"code/build_data/make_data.R",sep=""))

### Add in the modeled Race and income covariates for appendix Table A12 ###

source(paste(twd,"code/build_data/make_data_race_inc.R",sep=""))

log_close()


###########################
#### Main text analysis ###
###########################

log_open(paste(twd,"main_text.log", sep = "" ))

## Figure 1

source(paste(twd,"code/main_text/figure_1.R",sep=""))

## Table 1

source(paste(twd,"code/main_text/table_1.R",sep=""))

## Figure 2

source(paste(twd,"code/main_text/figure_2.R",sep=""))

## Table 2

source(paste(twd,"code/main_text/table_2.R",sep=""))

## Figure 3

source(paste(twd,"code/main_text/figure_3.R",sep=""))

## Table 3

source(paste(twd,"code/main_text/table_3.R",sep=""))

## Figure 4

source(paste(twd,"code/main_text/figure_4.R",sep=""))

log_close()

###########################
#### Appendix analysis ###
###########################

log_open(paste(twd,"appendix.log", sep = "" ))

## Table A1

source(paste(twd,"code/appendix/table_A1.R",sep=""))

## Table A2 

source(paste(twd,"code/appendix/table_A2.R",sep=""))

## Table A3 

source(paste(twd,"code/appendix/table_A3.R",sep=""))

## Table A4 

source(paste(twd,"code/appendix/table_A4.R",sep=""))

## Table A5

source(paste(twd,"code/appendix/table_A5.R",sep=""))


## Table A6

source(paste(twd,"code/appendix/table_A6.R",sep=""))

## Table A7

source(paste(twd,"code/appendix/table_A7.R",sep=""))

## Table A8

source(paste(twd,"code/appendix/table_A8.R",sep=""))

## Table A9

source(paste(twd,"code/appendix/table_A9.R",sep=""))

## Table A10

source(paste(twd,"code/appendix/table_A10.R",sep=""))

## Table A11

source(paste(twd,"code/appendix/table_A11.R",sep=""))


## Table A12

source(paste(twd,"code/appendix/table_A12.R",sep=""))

## Figure A1

source(paste(twd,"code/appendix/figure_A1.R",sep=""))

log_close()
